//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "HistoricalRatesAnalysis.h"
using namespace Cephei::QL::Models::Marketmodels;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/InterestRateIndex.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (boost::shared_ptr<QuantLib::HistoricalRatesAnalysis>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHistoricalRatesAnalysis = NULL;
#endif
	_ppHistoricalRatesAnalysis = &childNative;
    
}
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (QuantLib::HistoricalRatesAnalysis& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phHistoricalRatesAnalysis = NULL;
#endif
	_ppHistoricalRatesAnalysis = new boost::shared_ptr<QuantLib::HistoricalRatesAnalysis> (&childNative);
    
    _HistoricalRatesAnalysisOwner = owner;
    
}

Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (CHistoricalRatesAnalysis^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHistoricalRatesAnalysis = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppHistoricalRatesAnalysis = new boost::shared_ptr<QuantLib::HistoricalRatesAnalysis> (copy->GetShared());
        
    }
}
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (PLATFORM::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHistoricalRatesAnalysis = NULL;
#endif
	if (!t->IsSubclassOf(CHistoricalRatesAnalysis::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (QuantLib::Handle<QuantLib::HistoricalRatesAnalysis>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phHistoricalRatesAnalysis = &childNative;
	_ppHistoricalRatesAnalysis = &static_cast<boost::shared_ptr<QuantLib::HistoricalRatesAnalysis>>(childNative.currentLink());
    
    _HistoricalRatesAnalysisOwner = owner;
}
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (QuantLib::Handle<QuantLib::HistoricalRatesAnalysis> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phHistoricalRatesAnalysis = &childNative;
	_ppHistoricalRatesAnalysis = &static_cast<boost::shared_ptr<QuantLib::HistoricalRatesAnalysis>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::CHistoricalRatesAnalysis (QuantLib::HistoricalRatesAnalysis childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phHistoricalRatesAnalysis = NULL;
#endif
	_ppHistoricalRatesAnalysis = new boost::shared_ptr<QuantLib::HistoricalRatesAnalysis> (new QuantLib::HistoricalRatesAnalysis (childNative));
    
}
#endif

Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::~CHistoricalRatesAnalysis ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppHistoricalRatesAnalysis != NULL)
    {
	    delete _ppHistoricalRatesAnalysis;
        _ppHistoricalRatesAnalysis = NULL;
    }
}
Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::!CHistoricalRatesAnalysis ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppHistoricalRatesAnalysis != NULL)
    {
	    delete _ppHistoricalRatesAnalysis;
    }
}
QuantLib::HistoricalRatesAnalysis& Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::GetReference ()
{
    if (_ppHistoricalRatesAnalysis == NULL) throw REFNEW NativeNullException ();
	return **_ppHistoricalRatesAnalysis;
}
boost::shared_ptr<QuantLib::HistoricalRatesAnalysis>& Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::GetShared ()
{
    if (_ppHistoricalRatesAnalysis == NULL) throw REFNEW NativeNullException ();
	return *_ppHistoricalRatesAnalysis;
}
QuantLib::HistoricalRatesAnalysis* Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::GetPointer ()
{
    if (_ppHistoricalRatesAnalysis == NULL) throw REFNEW NativeNullException ();
	return &**_ppHistoricalRatesAnalysis;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::HistoricalRatesAnalysis>& Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::GetHandle ()
{
	if (_phHistoricalRatesAnalysis == NULL)
	{
		_phHistoricalRatesAnalysis = new Handle<QuantLib::HistoricalRatesAnalysis> (*_ppHistoricalRatesAnalysis);
	}
	return *_phHistoricalRatesAnalysis;
}
#endif
bool Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::HasNative () 
{
	return (_ppHistoricalRatesAnalysis != NULL);
}

Cephei::Core::IVector<DateTime>^ Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::SkippedDates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppHistoricalRatesAnalysis)->skippedDates ( );   
        Cephei::Core::IVector<DateTime>^ _nrv = REFNEW CoVector<DateTime> (REFNEW CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<String^>^ Cephei::QL::Models::Marketmodels::CHistoricalRatesAnalysis::SkippedDatesErrorMessage::get ()
{
    try
    {
    	std::vector<std::string>& _rv = (std::vector<std::string>&)(*_ppHistoricalRatesAnalysis)->skippedDatesErrorMessage ( );   
        Cephei::Core::IVector<String^>^ _nrv = REFNEW CoVector<String^> (REFNEW CStringVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

